package stack;

import java.util.ArrayList;
import java.util.EmptyStackException;
import java.util.List;

public class MyListStack<T> implements MyStack<T> {

    private List<T> list;

    public MyListStack() {
        this.list = new ArrayList<>();
    }

    @Override
    public void push(T e) {
        list.add(e);
    }

    @Override
    public T pop() {
        if (isEmpty()) {
            throw new EmptyStackException();
        }
        return list.remove(list.size() - 1);
    }

    @Override
    public T peek() {
        if (isEmpty()) {
            throw new EmptyStackException();
        }
        return list.get(list.size() - 1);
    }

    @Override
    public boolean isEmpty() {
        return list == null || list.isEmpty();
    }

    @Override
    public String toString() {
        return "MyListStack{" +
                "list=" + list +
                '}';
    }
}
